package com.snopy.concurrency.createthread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author snopy
 * @version 1.0.0
 * @classname RunnableDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/06/22 16:05
 */
public class RunnableDemo {
    public static void main(String[] args) {
        TaskRun taskRun = new TaskRun(5);
        Thread thread = new Thread(taskRun, "taskThread");
        Thread thread1 = new Thread(taskRun, "taskThread1");
        thread.start();

        try {
            thread.join(5000);
            thread1.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("over");
    }
}
@Slf4j
class TaskRun implements Runnable{

    private int num;

    public TaskRun(int num) {
        this.num = num;
    }

    @Override
    public void run() {
        log.info("this is a thread created by runnable!---{}",num);
        try {
            while (num>0){
                log.info("num:{}",num);

                TimeUnit.SECONDS.sleep(num--);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}